<template>
<div>
    <h2>转购研习社统计</h2>
       <div class="buttoncon">
       <Button type="primary"   @click="go" >返回上一页</Button>
       <Col span="8">
         <span>日期：</span>
            <DatePicker type="daterange" placement="bottom-end" placeholder="选择日期" style="width: 200px" @on-change="change"></DatePicker>
        </Col>
        
    </div>
    <Table border :loading="loading" :columns="columns2"  :data="data2" class="totalls"></Table>
        <Table border :loading="loading" :columns="columns1"  :data="data1"></Table>
        <div class="pages">
            <Page :total="pageTotal" :current="pageNum" :page-size="pageSize" show-elevator show-total 
placement="top" @on-change="handlePage" @on-page-size-change='handlePageSize'></Page>
        </div>
            

         <!-- <Switch v-model="loading"></Switch> -->
</div>
   
</template>
<script>
    export default {
        data(){
            return{
              loading: true,
              pageTotal: 0,
             pageNum: 1,
             pageSize: 7,
             SKU:' ',
             starttime:'',
             endtime:'',
             columns2:[
                   {
                        title: '总和',
                        key: 'datetotal',
                        align: 'center'
           
                    },
                    {
                        title: '19商',
                        key: 'sxy19Zyxscount',
                        align: 'center'
           
                    },
                         {
                        title: '18商',
                        key: 'sxy18Zyxscount',
                        align: 'center'
           
                    }   ,  {
                        title: '创新院',
                        key: 'cxyZyxscount',
                        align: 'center'
           
                    }   ,  {
                        title: '18商+19商',
                        key: 'sxy18Andsxy19Zyxscount',
                        align: 'center'
           
                    }  ,  
                     {
                        title: '18商+创新院',
                        key: 'sxy18AndcxyZyxscount',
                        align: 'center'
           
                    },
                    {
                        title: '19商+创新院',
                        key: 'sxy19AndcxyZyxscount',
                        align: 'center'
           
                    },
                        {
                        title: '18商+19商+创新院',
                        key: 'sxy18Andsxy19AndcxyZyxscount',
                        align: 'center'
           
                    },
                     {
                        title: '总累计',
                        key: 'totalkist',
                        align: 'center'
           
                    }
             ],
             data2:[],
                columns1: [
                    {
                        title: '日期',
                        key: 'date_z',
                        align: 'center'
           
                    },
                    {
                        title: '19商',
                        key: 'sxy19Zyxs',
                        align: 'center',
                                 render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                                this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy19",
                                                            sku_z:"date_yxs",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                    
                                        }
                                    }
                                },  params.row.sxy19Zyxs)
                          
                           
                        }
                
                    },
                      {
                        title: '18商',
                        key: 'sxy18Zyxs',
                        align: 'center',
                                 render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                                this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy",
                                                            sku_z:"date_yxs",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                      
                                        }
                                    }
                                },  params.row.sxy18Zyxs)
                          
                           
                        }
             
                    },
                               {
                        title: '创新院',
                        key: 'cxyZyxs',
                        align: 'center',
                             render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                               this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "cxy",
                                                            sku_z:"date_yxs",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                     
                                        }
                                    }
                                },  params.row.cxyZyxs)
                          
                           
                        }
                    },
                     {
                        title: '18商+19商',
                        key: 'sxy18Andsxy19Zyxs',
                        align: 'center',
                              render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                              this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy-sxy19",
                                                            sku_z:"date_yxs",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                
                                        }
                                    }
                                },  params.row.sxy18Andsxy19Zyxs)
                          
                           
                        }
                    },
                    {
                        title: '18商+创新院',
                        key: 'sxy18AndcxyZyxs',
                        align: 'center',
                                render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',
                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                              this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy-cxy",
                                                            sku_z:"date_yxs",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                      
                                        }
                                    }
                                },  params.row.sxy18AndcxyZyxs)
                          
                           
                        }
                    },
                     {
                        title: '19商+创新院',
                        key: 'sxy19AndcxyZyxs',
                        align: 'center',
                                   render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                              this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy19-cxy",
                                                            sku_z:"date_yxs",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                
                                        }
                                    }
                                },  params.row.sxy19AndcxyZyxs)
                          
                           
                        }

                    },
                     {
                        title: '18商+19商+创新院',
                        key: 'sxy18Andsxy19AndcxyZyxs',
                        align: 'center',
                                   render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                               this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy-sxy19-cxy",
                                                            sku_z:"date_yxs",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                                        }
                                    }
                                },  params.row.sxy18Andsxy19AndcxyZyxs)
                          
                           
                        }
                    },
                     {
                        title: '累计',
                        key: 'conut',
                        align: 'center'
                    }
                ],
                data1: [],
            datacxy:{
                datetotal:"合计",
                  sxy19Zyxscount:0,
               sxy18Zyxscount:0,
               cxyZyxscount:0,
              sxy18Andsxy19Zyxscount:0,
                sxy18AndcxyZyxscount:0,
               sxy19AndcxyZyxscount:0,
                sxy18Andsxy19AndcxyZyxscount:0,
                 totalkist:0
                }
            }
        },
    created(){
          var that =this;
          this.SKU=this.$route.query.Skus;
         console.log(this.$route.query.Skus)
this.getTeacherMessages()
 
    },
 methods: {
    // 日期改变-------------------------------------------------------
    change(key,v){
       console.log(key[0])
         this.starttime=key[0];
         this.endtime=key[1];
         if (key[0]!="") 
           {
             this.$Message.success('成功');
           }
         this.getTeacherMessages()
    },
      handlePage(value) {
      this.pageNum = value
      this.getTeacherMessages()
    },
    handlePageSize(value) {
      this.pageSize = value
      this.getTeacherMessages()
    },
    getTeacherMessages(){
   // 列表数据请求------------------------------------------------------------
        var that =this
        var pagenum=this.pageNum-1
        if (this.starttime=="" || this.endtime=="") 
            {
                var URL=this.Util.URL()+'/v1/buy-stat/stat-daily?sku='+this.SKU+'&page='+pagenum+'&page_size='+this.pageSize
            }else{
                 var URL=this.Util.URL()+'v1/buy-stat/stat-daily?sku='+this.SKU+'&page='+pagenum+'&page_size='+this.pageSize+'&date_from='+  this.starttime+'&date_end='+ this.endtime;
            }
            
         
        this.axios({
      method: 'get',
      url: URL
    })
    .then(function (response) {
        console.log(response.data.data);
          that.datalist(response.data.data)
        that.pageTotal= parseInt(response.data.data.total_count);
    })
    .catch(function (error) {
      console.log(error)
    }).finally(() => this.loading = false)
    },
    // 数据列表-----------------------------------------------------------------------
   datalist(Datalist){
     this.data2.length=0;
     var that =this;
            for (var i = 0; i < Datalist.allCount.length; i++) {
           var  Data = Datalist.allCount[i]
           that.datacxy.sxy19Zyxscount=parseInt(Data.sxy19Zyxs)
           that.datacxy.sxy18Zyxscount=parseInt(Data.sxy18Zyxs)
           that.datacxy.cxyZyxscount=parseInt(Data.cxyZyxs)
           that.datacxy.sxy18Andsxy19Zyxscount=parseInt(Data.sxy18Andsxy19Zyxs)
           that.datacxy.sxy18AndcxyZyxscount=parseInt(Data.sxy18AndcxyZyxs)
           that.datacxy.sxy19AndcxyZyxscount=parseInt(Data.sxy19AndcxyZyxs)
           that.datacxy.sxy18Andsxy19AndcxyZyxscount=parseInt(Data.sxy18Andsxy19AndcxyZyxs)
        }
        that.datacxy.totalkist=parseInt(Data.sxy19Zyxs)+parseInt(Data.sxy18Zyxs)+parseInt(Data.cxyZyxs)+
        parseInt(Data.sxy18Andsxy19Zyxs)+parseInt(Data.sxy18AndcxyZyxs)+parseInt(Data.sxy19AndcxyZyxs)+parseInt(Data.sxy18Andsxy19AndcxyZyxs)
         this.data2.push({
        datetotal: that.datacxy.datetotal,
                  sxy19Zyxscount:that.datacxy.sxy19Zyxscount,
               sxy18Zyxscount:that.datacxy.sxy18Zyxscount,
               cxyZyxscount:that.datacxy.cxyZyxscount,
              sxy18Andsxy19Zyxscount:that.datacxy.sxy18Andsxy19Zyxscount,
                sxy18AndcxyZyxscount: that.datacxy.sxy18AndcxyZyxscount,
               sxy19AndcxyZyxscount: that.datacxy.sxy19AndcxyZyxscount,
                sxy18Andsxy19AndcxyZyxscount: that.datacxy.sxy18Andsxy19AndcxyZyxscount,
                totalkist:that.datacxy.totalkist
                })

               this.data1.length=0
        for (var i = 0; i <Datalist.list.length; i++) {
             var  Data = Datalist.list[i]

          this.data1.push({
            date_z:Data.date_z,
            sxy19Zyxs:Data.sxy19Zyxs,
            sxy18Zyxs:Data.sxy18Zyxs,
            cxyZyxs:Data.cxyZyxs,
            sxy18Andsxy19Zyxs:Data.sxy18Andsxy19Zyxs,
            sxy18AndcxyZyxs:Data.sxy18AndcxyZyxs,
            sxy19AndcxyZyxs:Data.sxy19AndcxyZyxs,
            sxy18Andsxy19AndcxyZyxs:Data.sxy18Andsxy19AndcxyZyxs,
            conut:parseInt(Data.sxy19Zyxs)+parseInt(Data.sxy18Zyxs)+parseInt(Data.cxyZyxs)+parseInt(Data.sxy18Andsxy19Zyxs)+parseInt(Data.sxy18AndcxyZyxs)+parseInt(Data.sxy19AndcxyZyxs)+parseInt(Data.sxy18Andsxy19AndcxyZyxs)
          }



          )
        }

   },
            go() {
             this.$router.back(-1)
            }
 }
        
    }
</script>
<style scoped>
 h2{
        text-align: center;
        margin-bottom: 10px;
     }
     .pages {
      margin:16px 0;
        display: flex;
        justify-content: flex-end;
     }
     .buttoncon{
 margin:16px 0;
        display: flex;
        justify-content: space-between;
     }
     .totalls{
        margin-bottom: 20px;
     }

</style>